package model

import (
	"gorm.io/gorm"
	"time"
	"weibo_1006/global"
)

type Follow struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:id;primaryKey;not null;" json:"id"` // id
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" json:"user_id"`         // 用户ID
	FollowId  int32          `gorm:"column:follow_id;type:int;comment:关注用户ID;not null;" json:"follow_id"`   // 关注用户ID
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime;default:NULL;" json:"deleted_at"`
}

func (f *Follow) TableName() string {
	return "follow"
}

// 关注用户
func (f *Follow) AddFollow() error {
	return global.DB.Create(&f).Error
}

// 取消关注
func (f *Follow) DeleteFollow() error {
	return global.DB.Delete(&f).Error
}

// 查看粉丝
func (f *Follow) FindFollowUser(id int32) (list []Follow, err error) {
	err = global.DB.Where("follow_id = ?", id).Find(&list).Error
	return
}
